home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / util / gnu / emacs_src_18_58.lha / emacs-18.58 / src / amiga_term.c < prev    next >
C/C++ Source or Header  |  1992-05-23  |  8KB  |  341 lines

  1. /* Amiga terminal control routines.
  2.    Copyright (C) 1985, 1986, 1987 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU Emacs.
  5.  
  6. GNU Emacs is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GNU Emacs is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU Emacs; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. #include <stdio.h>
  22. #include <ctype.h>
  23. #include "config.h"
  24. #include "termhooks.h"
  25. #include "termchar.h"
  26. #include "termopts.h"
  27.  
  28. /* internal state */
  29.  
  30. /* nonzero means supposed to write text in standout mode.  */
  31. static int standout_requested;
  32.  
  33. static int standout_mode;    /* Nonzero when in standout mode.  */
  34.  
  35. static char tens[100] = {
  36.     '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
  37.     '1', '1', '1', '1', '1', '1', '1', '1', '1', '1',
  38.     '2', '2', '2', '2', '2', '2', '2', '2', '2', '2',
  39.     '3', '3', '3', '3', '3', '3', '3', '3', '3', '3',
  40.     '4', '4', '4', '4', '4', '4', '4', '4', '4', '4',
  41.     '5', '5', '5', '5', '5', '5', '5', '5', '5', '5',
  42.     '6', '6', '6', '6', '6', '6', '6', '6', '6', '6',
  43.     '7', '7', '7', '7', '7', '7', '7', '7', '7', '7',
  44.     '8', '8', '8', '8', '8', '8', '8', '8', '8', '8',
  45.     '9', '9', '9', '9', '9', '9', '9', '9', '9', '9',
  46. };
  47.  
  48. static char ones[100] = {
  49.     '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
  50.     '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
  51.     '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
  52.     '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
  53.     '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
  54.     '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
  55.     '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
  56.     '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
  57.     '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
  58.     '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
  59. };
  60.  
  61. #define addnum(str, num) if (num < 100) \
  62.                              { *--str = ones[num]; *--str = tens[num]; } \
  63.                          else do { *--str = '0' + num % 10; num /= 10; } while (num != 0)
  64.  
  65. /* Cursor motion stuff (from cm.c) */
  66. static int curX, curY;
  67.  
  68. /* Move to absolute position, specified origin 0 */
  69.  
  70. Amove_cursor (row, col)
  71. {
  72.   char buf[32], *pos = buf + 32;
  73.  
  74.   if (curY == row && curX == col)
  75.     return;
  76.  
  77.   curX = col; curY = row;
  78.   *--pos = 'H';
  79.   col = col + 1; row = row + 1;
  80.   addnum(pos, col);
  81.   *--pos = ';';
  82.   addnum(pos, row);
  83.   *--pos = 0x9b;
  84.   emacs_output(pos, buf + 32 - pos);
  85.   if (pos < buf) abort();
  86. }
  87.  
  88.  
  89. Aring_bell ()
  90. {
  91.   emacs_output("\07", 1);
  92. }
  93.  
  94. Aset_terminal_modes ()
  95. {
  96. }
  97.  
  98. Areset_terminal_modes ()
  99. {
  100.   turn_off_highlight ();
  101. }
  102.  
  103. Aupdate_begin ()
  104. {
  105.   /* Hide cursor */
  106.   emacs_output("\x9b\x30\x20\x70", 4);
  107. }
  108.  
  109. Aupdate_end ()
  110. {
  111.   background_highlight ();
  112.   standout_requested = 0;
  113.   emacs_output("\x9b\x20\x70", 3); /* Show cursor */
  114. }
  115.  
  116.  
  117. /* Handle highlighting when TN_standout_width (termcap sg) is not specified.
  118.    In these terminals, output is affected by the value of standout
  119.    mode when the output is written.
  120.  
  121.    These functions are called on all terminals, but do nothing
  122.    on terminals whose standout mode does not work that way.  */
  123.  
  124. static turn_off_highlight ()
  125. {
  126.   if (standout_mode) emacs_output("\x9b""27m", 4);
  127.   standout_mode = 0;
  128. }
  129.  
  130. static turn_on_highlight ()
  131. {
  132.   if (!standout_mode) emacs_output("\x9b\x37m", 3);
  133.   standout_mode = 1;
  134. }
  135.  
  136. /* Set standout mode to the state it should be in for
  137.    empty space inside windows.  What this is,
  138.    depends on the user option inverse-video.  */
  139.  
  140. static background_highlight ()
  141. {
  142.   if (inverse_video)
  143.     turn_on_highlight ();
  144.   else
  145.     turn_off_highlight ();
  146. }
  147.  
  148. /* Set standout mode to the mode specified for the text to be output.  */
  149.  
  150. static
  151. highlight_if_desired ()
  152. {
  153.   if (!inverse_video == !standout_requested)
  154.     turn_off_highlight ();
  155.   else
  156.     turn_on_highlight ();
  157. }
  158.  
  159. /* External interface to control of standout mode.
  160.    Call this when about to modify line at position VPOS
  161.    and not change whether it is highlighted.  */
  162.  
  163. Areassert_line_highlight (highlight, vpos)
  164.      int highlight;
  165.      int vpos;
  166. {
  167.   standout_requested = highlight;
  168. }
  169.  
  170. /* Call this when about to modify line at position VPOS
  171.    and change whether it is highlighted.  */
  172.  
  173. Achange_line_highlight (new_highlight, vpos, first_unused_hpos)
  174.      int new_highlight, vpos, first_unused_hpos;
  175. {
  176.   standout_requested = new_highlight;
  177.  
  178.   move_cursor (vpos, 0);
  179.  
  180.   background_highlight ();
  181.   clear_end_of_line (first_unused_hpos);
  182.   reassert_line_highlight (new_highlight, curY);
  183. }
  184.  
  185. /* Erase operations */
  186.  
  187. /* clear from cursor to end of screen */
  188. Aclear_to_end ()
  189. {
  190.   background_highlight ();
  191.   emacs_output("\x9bJ", 2);
  192. }
  193.  
  194. /* Clear entire screen */
  195.  
  196. Aclear_screen ()
  197. {
  198.   background_highlight ();
  199.   emacs_output("\f", 1);
  200.   curX = curY = 0;
  201. }
  202.  
  203. /* Clear to end of line, but do not clear any standout marker.
  204.    Assumes that the cursor is positioned at a character of real text,
  205.    which implies it cannot be before a standout marker
  206.    unless the marker has zero width.
  207.  
  208.    Note that the cursor may be moved.  */
  209.  
  210. Aclear_end_of_line (first_unused_hpos)
  211.      int first_unused_hpos;
  212. {
  213.   if (curX >= first_unused_hpos)
  214.     return;
  215.  
  216.   background_highlight ();
  217.   emacs_output("\x9bK", 2);
  218. }
  219.  
  220. Aoutput_chars (string, len)
  221.      register char *string;
  222.      int len;
  223. {
  224.   highlight_if_desired ();
  225.  
  226.   curX += len;
  227.   emacs_output(string, len);
  228. }
  229.  
  230. /* If start is zero, insert blanks instead of a string at start */
  231.  
  232. Ainsert_chars (start, len)
  233.      register char *start;
  234.      int len;
  235. {
  236.   char buf[32], *pos = buf + 32;
  237.  
  238.   highlight_if_desired ();
  239.  
  240.   *--pos = '@';
  241.   addnum(pos, len);
  242.   *--pos = 0x9b;
  243.   emacs_output(pos, buf + 32 - pos);
  244.   if (pos < buf) abort();
  245.   if (start) emacs_output(start, len);
  246. }
  247.  
  248. Adelete_chars (n)
  249.      register int n;
  250. {
  251.   char buf[32], *pos = buf + 32;
  252.  
  253.   *--pos = 'P';
  254.   addnum(pos, n);
  255.   *--pos = 0x9b;
  256.   emacs_output(pos, buf + 32 - pos);
  257.   if (pos < buf) abort();
  258. }
  259.  
  260. /* Insert N lines at vpos VPOS.  If N is negative, delete -N lines.  */
  261.  
  262. Ains_del_lines (vpos, n)
  263.      int vpos, n;
  264. {
  265.   register int i = n > 0 ? n : -n;
  266.   char buf[32], *pos = buf + 32;
  267.  
  268.   if (n > 0)
  269.     {
  270.       i = n;
  271.       *--pos = 'L';
  272.     }
  273.   else
  274.     {
  275.       i = -n;
  276.       *--pos = 'M';
  277.     }
  278.   if (vpos + i >= screen_height) return;
  279.  
  280.   move_cursor (vpos, 0);
  281.   background_highlight ();
  282.   addnum(pos, i);
  283.   *--pos = 0x9b;
  284.   emacs_output(pos, buf + 32 - pos);
  285.   if (pos < buf) abort();
  286. }
  287.  
  288. Acalculate_costs (extra, costvec, ncostvec)
  289.      int extra;
  290.      int *costvec, *ncostvec;
  291. {
  292.   CalcLID(2, 40, extra, 0, costvec, ncostvec);
  293. }
  294.  
  295. Aset_terminal_window (size)
  296. int size;
  297. {
  298. }
  299.  
  300.  
  301. amiga_term_init ()
  302. {
  303.   must_write_spaces = FALSE;
  304.   min_padding_speed = 0;
  305.   memory_below_screen = FALSE;
  306.   meta_key = TRUE;
  307.   scroll_region_ok = FALSE;
  308.   line_ins_del_ok = TRUE;
  309.   char_ins_del_ok = FALSE;
  310.   fast_clear_end_of_line = TRUE;
  311.   no_redraw_on_reenter = FALSE;
  312.  
  313.   clear_screen_hook = Aclear_screen;
  314.   clear_end_of_line_hook = Aclear_end_of_line;
  315.   clear_to_end_hook = Aclear_to_end;
  316.   ins_del_lines_hook = Ains_del_lines;
  317.   change_line_highlight_hook = Achange_line_highlight;
  318.   insert_chars_hook = Ainsert_chars;
  319.   output_chars_hook = Aoutput_chars;
  320.   delete_chars_hook = Adelete_chars;
  321.   ring_bell_hook = Aring_bell;
  322.   reset_terminal_modes_hook = Areset_terminal_modes;
  323.   set_terminal_modes_hook = Aset_terminal_modes;
  324.   update_begin_hook = Aupdate_begin;
  325.   update_end_hook = Aupdate_end;
  326.   set_terminal_window_hook = Aset_terminal_window;
  327.   move_cursor_hook = Amove_cursor;
  328.   reassert_line_highlight_hook = Areassert_line_highlight;
  329.  
  330.   dont_calculate_costs = 1;
  331.   calculate_costs_hook = Acalculate_costs;
  332.  
  333.   /* Get screen size from system, or else from somewhere ...  */
  334.   get_screen_size (&screen_width, &screen_height);
  335.   /* Random defaults to avoid any problems */
  336.   if (screen_width <= 0) screen_width = 80;
  337.   if (screen_height <= 0) screen_height = 23;
  338.  
  339.   init_baud_rate ();
  340. }
  341.